package com.uenpay.im.ui.old.activity.wallet;

import com.qiyunxin.android.http.net.HttpInvokeItem;
import com.uenpay.im.configuration.APIConfiguration;
import com.uenpay.im.entities.HttpInvokeResult;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.util.ArrayList;

/**
 * @author SL
 * @copyRight http://www.qiyunxin.com
 * @function 获取收支明细类型
 */
public class GetSubjectListInvokItem extends HttpInvokeItem {

	public class GetSubjectListInvokItemResult extends HttpInvokeResult {
		public ArrayList<String> arrayList = new ArrayList<String>();
	}

	public GetSubjectListInvokItemResult getOutput() {
		return (GetSubjectListInvokItemResult) GetResultObject();
	}

	/**
	 * 获取收支明细类型
	 * 
	 */
	public GetSubjectListInvokItem() {
		String url = APIConfiguration.getBaseUrl() + "Purse/Purse/subjectList?"
				+ APIConfiguration.getCustIdAndToken();
		SetUrl(url);
	}

	@Override
	protected Object DeserializeResult(String responseBody) throws Exception {
		GetSubjectListInvokItemResult result = new GetSubjectListInvokItemResult();
		try {
			JSONObject json = new JSONObject(responseBody);
			result.status = json.optInt("status");
			result.msg = json.optString("msg");
			JSONArray arr = json.optJSONArray("data");
			if (arr == null) {
				return result;
			}

			for (int i = 0, size = arr.length(); i < size; i++) {
				result.arrayList.add(arr.optString(i));
			}
		} catch (JSONException e) {
			e.printStackTrace();
		}
		return result;
	}

}
